<?php
if(isset($_POST['action']))
{
    $db = new Database();
    if($_POST['action']=="viewListOfPoints")
    {
        $ID = $_POST['ID'];
        $getPoints = $db->query("SELECT * FROM tbdealer WHERE dealerCode='$ID' and expiryDate > CURDATE() LIMIT 5","array");
        $count = $db->query("SELECT * FROM tbdealer WHERE dealerCode='$ID' and expiryDate > CURDATE()","numrows");
        foreach($getPoints as $name){
            $loadID = $name['id'];
        }
        
?>
    <div style="float: left; width: 100%; margin-left: 100px;">
        <?php
            if(empty($name['firstName'])&&empty($name['lastName'])){
                ?>
                <label class="h3 align_center">
                    No Record Found
                </label>
                <?php
            }else{
                
        ?>
            <label class="h3">
                <?php
                if(@$_POST['secAction']=="lessButt"){
                ?>
                Name: <?php echo $name['firstName']. " " . $name['lastName'];?>
                <?php
                }
                ?>
            </label><br><br>
            <label class="h3">
                Total Records: <span class="h2"><?php echo $count; ?></span>
            </label>
            <?php
            foreach($getPoints as $data)
            {
                $dealerPoints = $data['pointsEarned'];
                foreach (extractForms($dealerPoints) as $key => $value) {
                    if(isset($total[$key]))
                        $total[$key] += $value; 
                    else
                        $total[$key] = $value;
                }
            }
            ?>
            <div style="width: 80%;margin-top: 10px; line-height: 20px; margin-left: 15px;">
                    <table class="table_accomodation" width=1000>
                        <!--thead>
                            <tr>
                                <th>#</th>
                                <?php
                                foreach($total as $k => $v){
                                    echo "<th class='".$k."'>".$k."</th>";
                                    $countSpan = count($total)+2;
                                    $count_td = count($total);
                                }
                                ?>
                            </tr>
                        </thead-->
                        <tbody id='loadMore'>
                            <?php
                            $ctt = 1;
                            foreach($getPoints as $data)
                            {
                                echo "<tr>";
                                //echo "<td id='count_".$loadID."' rel='0'>".$ctt."</td>";
                                $dealerPoints = $data['pointsEarned'];
                                $InvoiceNo = $data['InvoiceNo'];
                                echo "<td>".$InvoiceNo."</td>";
                                foreach (extractForms($dealerPoints) as $key => $value) {
                                    echo "<td>".$td." ".$value."<br>(".$key.")"."</td>";
                                }
                                echo "<td>".$data['expiryDate']."</td></tr>";
                                $ctt++;
                            }
                            //echo "<td>Total Points</td>";
                            //foreach($total as $k => $v){
                            //    echo "<td>".$v."</td>";
                            //}
                            ?>
                        <tr id="more_<?php echo $loadID; ?>">
                            <td colspan="<?php echo $countSpan;?>">
                                <div class="morebox">
                                <a href="#" class="more" id="<?php echo $loadID; ?>" rel="<?php echo $ID; ?>" numColspan="<?php echo $countSpan; ?>">more</a>
                                </div>
                            </td>
                        </tr>
                        </tbody>
                    </table>
            </div>
            <?php } ?>
    </div>
    
<?php
    }
}
